import 'dart:io';

void main(List<String> args) async {
  print('开始');
  // 做一个耗时的操作
  // String data = getNetworkData();
  // print(data);
  getNetworkDataAsync().then((result) {
    print(result);
  }).catchError((e) {
    print('错误原因：$e');
  });

  String token = await login();
  print(token);
  String userInfo = await getUserInfo();
  print(userInfo);

  print('结束');
}

getNetworkData() {
  sleep(Duration(seconds: 3));
  return '网络数据';
}

getNetworkDataAsync() {
  return Future(() {
    // 去做耗时操作
    sleep(Duration(seconds: 3));
    // return '网络数据';
    return Exception('网络异常');
  });
}

login() {
  return Future(() {
    sleep(Duration(seconds: 3));
    return 'token-10086';
  });
}

getUserInfo() {
  return Future(() {
    sleep(Duration(seconds: 2));
    return 'Jack 18';
  });
}
